﻿using MiniFox.Configurations;
using MiniFox.Exceptions.Configurations;

namespace MiniFox.Exceptions
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class ManagedException : Exception
    {
        GroupConfig _groupConfig;
        ExceptionDescriptionSetting _descriptionSetting;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="group"></param>
        /// <param name="code"></param>
        public ManagedException(string group, string code)
        {
            var section = ConfigurationFactory.GetConfig<ExceptionConfiguration>();

            this._groupConfig = section.GroupConfigs[group];
            this._descriptionSetting = this._groupConfig.Descriptions[code];
            
        }
        /// <summary>
        /// 
        /// </summary>
        public string GroupName
        {
            get
            {
                return this._groupConfig.Name;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public string HttpCode
        {
            get
            {
                return this._groupConfig.HttpCode;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public string ErrorCode
        {
            get
            {
                return this._descriptionSetting.Code;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public override string Message
        {
            get
            {
                return this._descriptionSetting.Description;
            }
        }
    }
}
